package com.heima.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Properties;
import java.util.concurrent.Future;

public class SendStart {


    public static void main(String[] args) {
        // 创建配置
        Properties props = new Properties();
        // kafka 集群，broker-list
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.200.130:9092");
        //消息key的序列化器
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        //消息value的序列化器
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        //构造生产者
        KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(props);
        //封装发送的消息
        ProducerRecord<String,String> record = new ProducerRecord<String, String>("topic","","hello kafka");
        // 发送消息
        kafkaProducer.send(record);
        //关闭资源
        kafkaProducer.close();

    }
}
